package fr.flambycrew.parser;

import org.junit.Test;

import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.html.HtmlForm;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import com.gargoylesoftware.htmlunit.html.HtmlSubmitInput;

import fr.flambycrew.util.PropertyReader;

public class ConnectIt {
	
	private static String LOGIN = PropertyReader.getValue("authent.login");
	private static String PASSWORD = PropertyReader.getValue("authent.password");
	
	@Test
	public void submittingForm() throws Exception {
		WebClient webClient = WebClientFactory.getWebClient();
		// Get the first page
		final HtmlPage page1 = webClient.getPage("http://flambycrew.lolbb.com/login");

		// Get the form that we are dealing with and within that form,
		// find the submit button and the field that we want to change.
		final HtmlForm form = page1.getFormByName("form_login");

		final HtmlSubmitInput button = form.getInputByName("login");
		form.getInputByName("username").setValueAttribute(LOGIN);
		form.getInputByName("password").setValueAttribute(PASSWORD);

		// Now submit the form by clicking the button and get back the second
		// page.
		button.click();

		System.out.println(((HtmlPage) webClient.getPage("http://flambycrew.lolbb.com/t1989-keziah-jones-4-dec-2013-stereolux#21557")).asXml());

		webClient.closeAllWindows();
	}

}
